package com.fbee.smartcommunities.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * ClassName: com.fbee.smartcommunities.utils
 * Datetime: 2024/8/28 下午5:55
 * Description:
 *
 * @author 汪佳泉
 * @version 1.0
 * @since 1.0
 */
public class IPUtil {

    // 获取IP地址，考虑到代理的问题
    public static String getIP(HttpServletRequest request){
        String ipAddress = request.getHeader("X-Forwarded-For");
        if (ipAddress == null) {
            ipAddress = request.getRemoteAddr();
        }
        if (ipAddress != null && ipAddress.indexOf(',') > 0) {
            ipAddress = ipAddress.substring(0, ipAddress.indexOf(','));
        }
        return ipAddress;
    }

}
